<template>
  <div>
    <!-- <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
      <el-radio-button :label="false">展开</el-radio-button>
      <el-radio-button :label="true">收起</el-radio-button>
    </el-radio-group> -->

    <el-menu
      default-active="1-4-1"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      :collapse="isCollapse"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <h3>{{isCollapse?"":"CRM管理系统"}}</h3>
      <el-menu-item
        v-for="item in noChildren"
        :key="item.name"
        :index="item.name"
        @click="changeMenu(item)"
      >
        <i :class="`el-icon-${item.icon}`"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>

      <el-submenu
        class="el-submenu"
        v-for="item in hasChildren"
        :key="item.name"
        :index="item.name"
      >
        <template slot="title">
          <i :class="`el-icon-${item.icon}`"></i>
          <span slot="title">{{ item.label }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            v-for="SubItem in item.children"
            :key="SubItem.name"
            @click="changeMenu(SubItem)"
            :index="SubItem.name"
            >{{ SubItem.label }}
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "RightAside",
  data() {
    return {
      // isCollapse: false,
      menuData: [
        {
          path: "/",
          name: "index",
          label: "首页",
          icon: "s-home",
          url: "/",
        },
        {
          label: "系统管理",
          icon: "s-custom",
          name: "system",
          children: [
            {
              path: "/system/sysUser",
              name: "SysUser",
              label: "用户管理",
              icon: "setting",
              url: "/sysUser",
              parentLabel:"系统管理"
            },
            {
              path: "/system/dept",
              name: "Dept",
              label: "部门管理",
              icon: "setting",
              url: "/dept",
              parentLabel:"系统管理"
            },
            {
              path: "/system/sysRole",
              name: "SysRole",
              label: "角色管理",
              icon: "setting",
              url: "/sysRole",
              parentLabel:"系统管理"
            },
            {
              path: "/system/sysMenu",
              name: "SysMenu",
              label: "菜单管理",
              icon: "setting",
              url: "/sysMenu",
              parentLabel:"系统管理"
            },
            {
              path: "/system/sysLog",
              name: "SysLog",
              label: "操作日志",
              icon: "setting",
              url: "/sysLog",
              parentLabel:"系统管理"
            },
          ],
        },
        {
          label: "客户管理",
          icon: "s-custom",
          name: "customer",
          children: [
            {
              path: "/customer/customerList",
              name: "CustomerList",
              label: "客户列表",
              icon: "setting",
              url: "/customerList",
              parentLabel:"客户管理"
            },
            {
              path: "/customer/commonCustomer",
              name: "CommonCustomer",
              label: "公海客户",
              icon: "setting",
              url: "/commonCustomer",
              parentLabel:"客户管理"
            },
          ],
        },
        {
          label: "营销管理",
          icon: "s-order",
          name: "market",
          children: [
            {
              path: "/market/allOrder",
              name: "AllOrder",
              label: "全部订单",
              icon: "setting",
              url: "allOrder",
              parentLabel:"订单管理"
            },
            {
              path: "/market/myOrder",
              name: "MyOrder",
              label: "我的订单",
              icon: "setting",
              url: "myOrder",
              parentLabel:"订单管理"
            },
          ],
        },
        {
          label: "服务管理",
          icon: "s-order",
          name: "server",
          children: [
            
          ],
        },
      ],
    };
  },
  computed: {
    hasChildren() {
      return this.menuData.filter((item) => item.children);
    },
    noChildren() {
      return this.menuData.filter((item) => !item.children);
    },
    isCollapse(){
      return this.$store.state.tab.isCollapse
    },
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    changeMenu(item){
      this.$store.commit('tagChange',item)
      if(this.$route.path===item.path){
        return
      }
      this.$router.push(item.path)
      this.$store.commit('menuChange',this.$route.matched)
    },
  },
};
</script>

<style lang="less" scoped>
.el-submenu{
  width:200px;
}
.el-menu {
  border-right: none;
  height: 120vh;
  h3{
    color:#cad4d3;
    position: relative;
    width: 100%;
    height: 20px;
    line-height: 20px;
    text-align:center;
    overflow: hidden;
  }
}
</style>